package com.sirun.cn.fca.module.main.home.temp.control.block;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sirun.cn.fca.R;
import com.tencent.cloud.iov.block.BaseBlockLayout;
import com.tencent.cloud.iov.block.Block;

@Block
public class OperationBlockLayout extends BaseBlockLayout<IOperationBlockItem> implements View.OnClickListener{
    private TextView mLocationTV, mTimeTV;
    private LinearLayout mBeerLL, mLockLL, mUnlockLL, mEngineOnLL, mEngineOffLL;

    @Override
    protected View createView(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_control_location, parent, false);
        mLocationTV = view.findViewById(R.id.tv_control_location);
        mTimeTV = view.findViewById(R.id.tv_location_time);
        mBeerLL = view.findViewById(R.id.ll_control_beer);
        mLockLL = view.findViewById(R.id.ll_control_lock);
        mUnlockLL = view.findViewById(R.id.ll_control_unlock);
        mEngineOnLL = view.findViewById(R.id.ll_control_engine_on);
        mEngineOffLL = view.findViewById(R.id.ll_control_engine_off);

        mBeerLL.setOnClickListener(this);
        mLockLL.setOnClickListener(this);
        mUnlockLL.setOnClickListener(this);
        mEngineOnLL.setOnClickListener(this);
        mEngineOffLL.setOnClickListener(this);
        return view;
    }

    @Override
    protected void bindView(IOperationBlockItem item, int position) {
        mLocationTV.setText(item.getCarLocationText());
        mTimeTV.setText(item.getCarTimeString());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_control_beer:
                onAction(IOperationAction.ACTION_CLICK_BEER);
                break;
            case R.id.ll_control_lock:
                onAction(IOperationAction.ACTION_CLICK_LOCK);
                break;
            case R.id.ll_control_unlock:
                onAction(IOperationAction.ACTION_CLICK_UNLOCK);
                break;
            case R.id.ll_control_engine_on:
                onAction(IOperationAction.ACTION_CLICK_ENGINEON);
                break;
            case R.id.ll_control_engine_off:
                onAction(IOperationAction.ACTION_CLICK_ENGINEOFF);
                break;
        }
    }
}
